<!--
 * @Description:
 * @Version: 0.1
 * @Autor: Civet
 * @Date: 2019-08-02 16:04:58
 * @LastEditors: Civet
 * @LastEditTime: 2019-09-09 10:15:13
 -->
<template>
  <loginView
    @sub="sub"
  >
  </loginView>
</template>

<script>
  import loginView from './loginView'
  import {login} from "@/httpUtils/apiHome";
  export default {

    components: {
      loginView
      // name
    },
    name: "loginLogic",
    props: {
      // msg: String //  [name: typeof]
    },
    filters: {},
    computed: {},
    watch: {},
    data() {
      return {}
    },
    created() {

    },
    mounted() {
      console.log("123", location.href);
    },
    methods: {
      sub(us) {
        window.sessionStorage.setItem('userData',JSON.stringify({"access_token":"ba85fdc5-d861-49e9-a2c8-1c66e67539e3","token_type":"bearer","refresh_token":"bb90e07d-049c-4d19-9c8d-5e76d2d72159","expires_in":194103,"scope":"app"}))
        this.$router.push('/frame')
        if (us.password == '' || us.username == '') {
          this.$message({
            type: 'error',
            message: '用户名或密码不能为空!'
          });
          return;
        }

        let newObj = {
          pwd: us.password,
          userName: us.username
        }
        login(newObj).then((res) => {

          if (res.status == 200) {
            switch (res.data.code) {
              case 9999 :
                this.$message({
                  type: 'error',
                  message: `${res.data.message}！`
                });
                break;
              case 9998:
                this.$message({
                  type: 'error',
                  message: `${res.data.message}！`
                });
                break;
              case 9997:
                this.$message({
                  type: 'error',
                  message: `${res.data.message}！`
                });
                break;
              case 0:
                let session = window.sessionStorage;
                let userData = res.data.data;
                session.setItem("userData", userData);
                this.$router.push('/frame');
                break;
            }
          }
        }).catch((err) => {
          console.log('loginerr', err);
        });
      }
    },
    destroyed() {

    }
  }
</script>

<style scoped lang="less">

</style>
